<?php
/**
 *
 */
class TypesController extends AppController {
    var $name = 'Types';

    var $pageTitle = 'Type Description';

    var $viewPath = 'its/inventories/types';

    var $uses = array('ItsType');

    var $helpers = array('Html', 'Form', 'Ajax', 'My');

    function beforeFilter() {
        parent::beforeFilter();
        $this->set('parentNav', 'its_inventories');
        $this->set('tabMenu', 'its/ItsInventories/tabMenus');
    }

    function display() {
        parent::display();
        $this->_paging('ItsType', 'LIKE');
    }

//    function save() {
//        $view = 'view';
//        if (!empty($this->data)) {
//            $this->data['ItsType']['collector_id'] = $this->Session->read('Auth.User.id');
//            if($this->ItsType->save($this->data)) {
//                $this->Session->setFlash("Type code {$this->data['ItsType']['code']} save succesfull.", 'flash/ok');
//                $this->data = null;
//                $this->setAction('display');
//                return;
//            }
//        }
//        $this->setAction('view');
//    }

    function view($id = null) {
        // edit
        if ($id != null) {
            $this->data = $this->ItsType->findById($id);

            $this->ItsType->id = $id;
            $this->set('neighbors', $this->ItsType->find('neighbors', array('fields' => array('id', 'name'))));
            $this->set('mode', 'edit');
        } else {
            $this->set('mode', 'add');
        }

        $this->render('view');
    }

    function delete($id = null) {
        if ($this->ItsType->delete($id)) {
            $this->Session->setFlash("Type delete succesfull.", 'flash/ok');
        } else {

        }
        $this->setAction('display');
    }

}
?>
